package com.bird.thread.base.thread;

/**
 * @author: bird
 * @Data: 2021/7/2 10:35
 * @description: 说明： 线程sleep的时候 不释放synchronized的monitor,等sleep时间到了才释放锁。
 */
public class SleepDontReleaseMonitor implements Runnable {

    public static void main(String[] args) {
        SleepDontReleaseMonitor sdr = new SleepDontReleaseMonitor();
        new Thread(sdr).start();
        new Thread(sdr).start();
    }


    @Override
    public void run() {
        syn();
    }


    private synchronized void syn() {
        System.out.println("线程" + Thread.currentThread().getName() + " 获取到了monitor");

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("线程 " + Thread.currentThread().getName() + "退出了同步代码块");
    }
}
